import { defineStore } from 'pinia';
import { resetAllStores } from './setup';
import { useAppStore } from './app';
import { useUserStore } from './user';

export const useAuthStore = defineStore(
  'wos-auth',
  () => {
    const userStore = useUserStore();
    const appStore = useAppStore();

    async function logout() {
      resetAllStores();
      userStore.setLoginExpired(false);
      userStore.setUserInfo({
        avatar: '',
        userId: '',
        username: '',
      });
      appStore.logout();
    }

    function $reset() {
      appStore.setShowLogin(true);
    }
    return {
      $reset,
      logout,
    };
  },
  {
    persist: true,
  },
);
